package window;

import cn.hutool.core.date.DateTime;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @Author: youdao.hww
 * @Date: 10/20/24
 * @Desc:
 */
public class DateTimeTest2 {

    public static final String DATE_FORMAT = "yyyy-MM-dd";

    public static final String DATE_TIME_FORMAT = "yyyy-MM-dd HH:mm:ss";

    public static void main(String[] args) {
        //启用时间
        Date enableTime = parseStrToDate("2024-10-20 15:10:00", "yyyy-MM-dd HH:mm:ss");
        //服务时间
        Date serviceTimeStart = parseStrToDate("2024-10-20 06:00:00", "yyyy-MM-dd HH:mm:ss");

        //如果启用是在服务时间之后的话,以启用时间为准
        if (enableTime.after(serviceTimeStart)) {
            System.out.println("true");
        } else {
            System.out.println("false");
        }
    }


    public static Date parseStrToDate(String time, String timeFromat) {
        if (time == null || "".equals(time)) {
            return null;
        }

        Date date = null;
        try {
            DateFormat dateFormat = new SimpleDateFormat(timeFromat);
            date = dateFormat.parse(time);
        } catch (Exception e) {

        }
        return date;
    }

    public static Date getDate(String date, String format) {
        SimpleDateFormat df = new SimpleDateFormat(format);
        try {
            return df.parse(date);
        } catch (ParseException e) {
        }
        return null;
    }


    public static String getDate(Date date, String format) {
        return parse(date, format);
    }

    public static String parse(Date date, String formatString) {
        return toString(date, formatString);
    }


    public static String toString(Date currentDate, String dateTimeFormat) {
        DateTime dateTime = new DateTime(currentDate);
        return dateTime.toString(dateTimeFormat);
    }
}
